package net.pinnoocle.playshoppc.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.pinnoocle.playcommon.response.BaseResult;
import net.pinnoocle.playdao.entity.shopPc.WechatSettingDetailVo;
import net.pinnoocle.playdao.entity.shopPc.applet.SaveWechatSettingParams;
import net.pinnoocle.playservice.service.CommonService;
import net.pinnoocle.playservice.service.impl.ShopWechatSettingServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author ye
 * @Description
 * @create 2021-10-29 17:07
 */
@RestController
@RequestMapping("/wechat")
@Api(tags = "小程序&支付相关设置")
public class WechatController {

    @Autowired
    ShopWechatSettingServiceImpl wechatSettingService;
    @Autowired
    CommonService commonService;

    @GetMapping("settingDetail")
    @ApiOperation("小程序相关设置回显")
    public BaseResult<WechatSettingDetailVo> settingDetail(){
        return new BaseResult<WechatSettingDetailVo>().ok(wechatSettingService.settingDetail());
    }

    @PostMapping("wechatSetting")
    @ApiOperation("小程序&支付相关设置")
    public BaseResult<String> wechatSetting(@RequestBody SaveWechatSettingParams params){
        boolean result = wechatSettingService.wechatSetting(params);
        if(result){
            return new BaseResult<String>().success("设置成功");
        }
        return new BaseResult<String>().error("设置失败");
    }

    @PostMapping("/uploadCert")
    @ApiOperation("上传支付证书")
    public BaseResult<String> uploadCert(@RequestParam("file") MultipartFile file){
        return new BaseResult<String>().ok(wechatSettingService.uploadCert(file));
    }
}
